package com.Mapper;

import com.Bean.User;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;
@Service("userDaoImpl")
@Transactional
public class UserDaoImpl  implements UserMapper {


   private SqlSessionTemplate sqlSession;

      @Autowired
      public void setSqlSession(SqlSessionTemplate sqlSession) {
          this.sqlSession = sqlSession;
      }

    public List<User> selectUser() {
        User user = new User(38, "帅哦去", new Date());
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        mapper.addUser(new User(41,"tianxia",new Date()));
        mapper.updateUser(user);
        return mapper.selectUser();
    }

    public int addUser(User user) {
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        return mapper.addUser(user);
    }

    public int updateUser(User user) {
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        return mapper.updateUser(user);
    }
}
